local bingde = fk.CreateSkill{
  name = "hanqing__bingde",
}

Fk:loadTranslationTable{
  ["hanqing__bingde"] = "摒得",
  [":hanqing__bingde"] = "当你造成伤害后，可以获得中央区一张非伤害牌，然后反转〖市势〗中对应类型的比例；"..
  "若〖市势〗中所有比例均小于1，你受到伤害亦可发动〖摒得〗。",

  ["#hanqing__bingde-prey"] = "摒得：获得其中一张牌，反转“市势”对应类型的比例",
}

local spec = {
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = table.filter(room:getBanner("@$CenterArea"), function (id)
      return not Fk:getCardById(id).is_damage_card
    end)
    local card = room:askToChooseCard(player, {
      target = player,
      flag = { card_data = {{ "@$CenterArea", cards }} },
      skill_name = bingde.name,
      prompt = "#hanqing__bingde-prey",
    })
    local type = Fk:getCardById(card):getTypeString()
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, bingde.name, nil, true, player)
    if player.dead or not player:hasSkill("hanqing__shishi", true) then return end
    room:setPlayerMark(player, "hanqing__shishi_"..type, player:getMark("hanqing__shishi_"..type) > 0 and 0 or 1)
  end,
}

bingde:addEffect(fk.Damage, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(bingde.name) and
      table.find(player.room:getBanner("@$CenterArea"), function (id)
        return not Fk:getCardById(id).is_damage_card
      end)
  end,
  on_use = spec.on_use,
})

bingde:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(bingde.name) and
      table.every({"basic", "trick", "equip"}, function (type)
        return player:getMark("hanqing__shishi_"..type) > 0
      end) and
      table.find(player.room:getBanner("@$CenterArea"), function (id)
        return not Fk:getCardById(id).is_damage_card
      end)
  end,
  on_use = spec.on_use,
})

bingde:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return bingde
